<?php
/**
 * 起点短信类
 * User: 王海东
 * Date: 2018/12/20
 * Time: 12:05
 */
namespace sms;
use app\common\model\Config;

class Qidian
{
    private $url;       //短信提交地址
    private $uName;     //短信账户
    private $uPass;     //短信密码

    public function __construct()
    {
        $sms = (new Config())->get('sms_qidian');

        $this->url      = $sms['url'];
        $this->uName    = $sms['name'];
        $this->uPass    = $sms['pass'];
    }

    /**
     * 手机短信验证
     * @author 王海东
     * @date
     * @param string $phone     手机号
     * @param string $content   短信内容
     * @return mixed
     * @throws \Exception
     */
    public function sendCodeToPhone(string $phone, string $content)
    :bool {
        $params['Uname']    = $this->uName;
        $params['Upass']    = md5($this->uPass);

        $params['Mobile']   = $phone;

        $sign =  (new Config())->get('web_title') ?? '验证码';

        $params['Content'] = "【".$sign."】 ".$content;

        $json = send_http($this->url, $params);

        $obj = json_decode($json);

        return $obj->Status == 1 ? true :false;
    }

}